﻿using System.Collections.Generic;
using System.Linq;
using ControleRepresentante.Logic.Models;

namespace WebSite.Controllers.ControllerExtensions
{
    public interface IControllerExtensionProvider
    {
        IControllerExtension[] GetExtensions(Area area, Representante representante);
    }

    public class ControllerExtensionProvider : IControllerExtensionProvider
    {
        private readonly List<IControllerExtension> m_ControllerExtensions;

        public ControllerExtensionProvider()
        {
            m_ControllerExtensions = new List<IControllerExtension>
            {
                new TransportadoraControllerJolitexExtension(),
                new FabricaControllerJolitexExtension(),
                new FabricaControllerTriviumExtension(),
                new ClienteControllerJolitexExtension(),
                new PedidoControllerJolitexExtension(),
                new RelatorioVisitaControllerJolitexExtension()
            };
        }

        protected void AddExtension(IControllerExtension controllerExtension)
        {
            m_ControllerExtensions.Add(controllerExtension);
        }

        public IControllerExtension[] GetExtensions(Area area, Representante representante)
        {
            return m_ControllerExtensions.Where(x => x.CanHandle(area, representante)).ToArray();
        }
    }
}